//
//  UnifiedNativeAdImageView.m
//  SAMKit_Example
//
//  Created by 山刘 on 2020/4/23.
//  Copyright © 2020 samlau7245. All rights reserved.
//

#import "UnifiedNativeAdImageView.h"

@implementation UnifiedNativeAdImageView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setUserInteractionEnabled:YES];
        
        [self addSubview:self.backView];
        self.backgroundColor = kColor_bg;
        
        self.adView = [[UnifiedNativeAdCustomView alloc] init];
        [self.backView addSubview:self.adView];
        //[self.backView addSubview:self.tagLabel];
    }
    return self;
}

- (void)setupWithUnifiedNativeAdDataObject:(GDTUnifiedNativeAdDataObject *)dataObject delegate:(id <GDTUnifiedNativeAdViewDelegate>)delegate vc:(UIViewController *)vc{
    self.adView.delegate = delegate; // adView 广告回调
    self.adView.viewController = vc; // 跳转 VC
//    [self.adView.logoView setHidden:YES];// 隐藏腾讯自带LOGO，用自定义 tagLabel 代替。
    
//    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.backView).mas_offset(17.0);
//        make.right.equalTo(self.backView).mas_offset(-15.0);
//        make.width.mas_equalTo(CGRectGetWidth(self.tagLabel.bounds));
//    }];
    
    self.backView.frame = CGRectMake(0, 5, LYScreenWidth(), UnifiedNativeAdImageViewHeight-5);
    self.adView.frame = self.backView.bounds;
    
    [self.adView.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.equalTo(self.adView).mas_offset(15.0);
        make.size.mas_equalTo(CGSizeMake(44.0, 44.0));
    }];
    self.adView.iconImageView.layer.cornerRadius = 2;
    self.adView.iconImageView.layer.masksToBounds = YES;

    self.adView.titleLabel.font = kFont_16;
    self.adView.titleLabel.textColor = kColor_1;
    [self.adView.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.adView.iconImageView.mas_right).mas_offset(10.5);
        make.right.equalTo(self.adView).mas_offset(-20);
        make.top.equalTo(self.adView.iconImageView.mas_top).mas_offset(2.0);
    }];

    self.adView.descLabel.font = [UIFont systemFontOfSize:13.0];
    self.adView.descLabel.textColor = kColor_3;
    [self.adView.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.adView.titleLabel);
        make.bottom.equalTo(self.adView.iconImageView.mas_bottom).mas_offset(-2.0);
    }];
    
    [self.adView setupWithUnifiedNativeAdObject:dataObject];
    [self.adView registerDataObject:dataObject clickableViews:@[self.adView]];// 注册点击视图响应事件
}
+ (CGFloat)cellHeightWithUnifiedNativeAdDataObject:(GDTUnifiedNativeAdDataObject *)dataObject{
    return UnifiedNativeAdImageViewHeight;
}

#pragma mark - Getter
//-(UILabel *)tagLabel{
//    if (!_tagLabel) {
//        _tagLabel = [[UILabel alloc] init];
//        _tagLabel.numberOfLines = 0;
//        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"广告" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0],NSForegroundColorAttributeName: kColor_3}];
//        _tagLabel.attributedText = string;
//        [_tagLabel sizeToFit];
//    }
//    return _tagLabel;
//}

-(UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc] init];
        _backView.backgroundColor = kColor_W;
    }
    return _backView;
}
@end
